package com.atguigu.juc.homework3;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
//作业   阻塞api的练习
public class BlockingQueueDemo {
    public static void main(String[] args) throws InterruptedException {

        BlockingQueue<String> blockingQueue = new ArrayBlockingQueue<>(3);
        //第一组
        /*blockingQueue.add("c");
        blockingQueue.add("y");
        blockingQueue.add("x");*/

       /* blockingQueue.remove();
        blockingQueue.remove();
        blockingQueue.remove();
        blockingQueue.remove();*/
        //blockingQueue.element();
       /* System.out.println(blockingQueue.element());
        System.out.println(blockingQueue.element());
        System.out.println(blockingQueue.element());
        System.out.println(blockingQueue.element());*/
       //第二组
   /*     System.out.println(blockingQueue.offer("c"));
        System.out.println(blockingQueue.offer("c"));
        System.out.println(blockingQueue.offer("c"));
        System.out.println(blockingQueue.offer("c"));

        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());
        System.out.println(blockingQueue.poll());*/

        //第三组
       /* new Thread(() -> {
            blockingQueue.put("c");  },"线程名称").start();*/
       /* blockingQueue.put("s");
        blockingQueue.put("s");
        blockingQueue.put("s");
        blockingQueue.put("s");*/

       //blockingQueue.take();
        //第四组
        /*blockingQueue.offer("c",1, TimeUnit.SECONDS);
        blockingQueue.offer("c",1, TimeUnit.SECONDS);
        blockingQueue.offer("c",1, TimeUnit.SECONDS);
        blockingQueue.offer("c",1, TimeUnit.SECONDS);*/
        blockingQueue.poll(1,TimeUnit.SECONDS);
        System.out.println(blockingQueue);
    }
}
